import { Suspense } from 'react'
import { Routes, Route, Navigate } from 'react-router-dom'
/* -------------------------------------------------------- data -- */
import PageLoading from '@tp/page-loading'
/* -------------------------------------------------------- 主路由数据 -- */
const mainRouter = [
	{ path:'main', component: 'index', outlet:true },
	{ path:'login' },
	{ path:'ws' },
	{ path:'sse' }
]
/* -------------------------------------------------------- 主路由数据 -- */
const _ = () => {
	return (
		<Suspense fallback={<PageLoading />}>
			<Routes>
				{
					mainRouter.map(({ path, component, outlet },i) => {
						path = path + ( outlet ? '/*' : '')
						component = component ? component : path
						return <Route key={i} path={path} Component={window.$lazy.router(component)} />
					})
				}
				<Route path='/' element={ <Navigate to='/main' replace /> } />
				<Route path='*' Component={ window.$lazy.router('404') } />
			</Routes>
		</Suspense>
	)
}

export default _